import Vue from 'vue'
import VueRouter from 'vue-router'
// import Login from '../components/Login.vue'
const Login = () => import(/* webpackChunkName: "login_home_welcome" */ '../components/Login.vue')
// import Home from '../components/Home.vue'
const Home = () => import(/* webpackChunkName: "login_home_welcome" */ '../components/Home.vue')
// import Welcome from '../components/Welcome.vue'
const Welcome = () => import(/* webpackChunkName: "login_home_welcome" */ '../components/Welcome.vue')
// import Users from '../components/user/User.vue'
const Users = () => import(/* webpackChunkName: "Users_Rights_Roles" */ '../components/user/User.vue')
// import Roles from '../components/rights/Roles.vue'
const Roles = () => import(/* webpackChunkName: "Users_Rights_Roles" */ '../components/rights/Roles.vue')
// import Rights from '../components/rights/Rights.vue'
const Rights = () => import(/* webpackChunkName: "Users_Rights_Roles" */ '../components/rights/Rights.vue')
// import Goods from '../components/goods/Goods.vue'
const Goods = () => import(/* webpackChunkName: "Goods_Params_Add" */ '../components/goods/Goods.vue')
// import Params from '../components/goods/Params.vue'
const Params = () => import(/* webpackChunkName: "Params_Categories_Add" */ '../components/goods/Params.vue')
// import Categories from '../components/goods/Categories.vue'
const Categories = () => import(/* webpackChunkName: "Params_Categories_Add" */ '../components/goods/Categories.vue')
// import Orders from '../components/orders/Orders.vue'
const Orders = () => import(/* webpackChunkName: "Orders_Reports" */ '../components/orders/Orders.vue')
// import Reports from '../components/reports/Reports.vue'
const Reports = () => import(/* webpackChunkName: "Orders_Reports" */ '../components/reports/Reports.vue')
// import Add from '../components/goods/Add.vue'
const Add = () => import(/* webpackChunkName: "Params_Categories_Add" */ '../components/goods/Add.vue')

Vue.use(VueRouter)

const routes = [
  { path: '/', redirect: '/login' },
  { path: '/login', component: Login },
  // eslint-disable-next-line object-property-newline
  { path: '/home', component: Home, redirect:'/welcome', children: [
    // eslint-disable-next-line object-curly-spacing
    {path:'/welcome', component: Welcome},
    // eslint-disable-next-line object-curly-spacing
    {path:'/users', component: Users},
    // eslint-disable-next-line object-curly-spacing
    {path:'/roles', component: Roles},
    // eslint-disable-next-line object-curly-spacing
    {path:'/rights', component: Rights},
    // eslint-disable-next-line object-curly-spacing
    {path:'/goods', component: Goods},
    // eslint-disable-next-line object-curly-spacing
    {path:'/params', component: Params},
    // eslint-disable-next-line object-curly-spacing
    {path:'/categories', component: Categories},
    // eslint-disable-next-line object-curly-spacing
    {path:'/orders', component: Orders},
    // eslint-disable-next-line object-curly-spacing
    {path:'/reports', component: Reports},
    // eslint-disable-next-line object-curly-spacing
    {path:'/goods/add', component: Add}
  ] }
]

const router = new VueRouter({
  routes
})
// 挂载路由导航守卫
router.beforeEach((to, from, next) => {
  // to是将要访问的路径
  // from是从那个路径过来
  // next是一个函数，表示放行
  if (to.path === '/login') return next()
  const tokenStr = window.sessionStorage.getItem('token')
  if (!tokenStr) return next('/login')
  next()
})
export default router
